<%@taglib  uri="/WEB-INF/struts-bean.tld"  prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%@taglib   uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<script language="JavaScript">
    function checkAll(field)
    {
        if(document.form1.checkall.checked == true)
        {
            for (i = 0; i < field.length; i++)
            {field[i].checked = true ;
            }
            return true;

        }else{
            for (i = 0; i < field.length; i++)
            {field[i].checked = false ;
            }
            return false;
        }

    }
    function check()
    {

        document.form1.list.checked==true;
    }

</script>
<script language="JavaScript">
    function show(){
        document.getElementById('frhotelidN').value ="";
        document.getElementById('frhotelnameN').value ="";
        document.getElementById('frhotelemailN').value ="";
        document.getElementById('frhotelwebN').value ="";
        document.getElementById('frhotelimageN').value ="";
        document.getElementById('frhotelrateN').value ="";
        document.getElementById('frhoteladdN').value ="";
        document.getElementById('frhotelphoneN').value ="";
        document.getElementById('frhotelcityN').value ="";
        document.getElementById('frhoteldesN').value ="";
        document.getElementById('frhotelidN').disabled= true;
        document.frN.style.visibility='visible';
        document.getElementById('frinsertN').style.visibility='visible';
        document.fr.style.visibility='hidden';
    }


    function showedit1(element){
        document.frN.style.visibility='hidden';
        document.fr.style.visibility='visible';
        document.getElementById('frinsertN').style.visibility='hidden';
        document.getElementById('frupdate').style.visibility='visible';
        document.getElementById('frdelete').style.visibility='hidden';
        document.getElementById('frhotelid').disabled= true;
        document.getElementById('frhotelidd').value = document.getElementById('fr1hotelid'+element).value;
        document.getElementById('frhotelid').value = document.getElementById('fr1hotelid'+element).value;
         document.getElementById('frhotelname').value = document.getElementById('fr1hotelname'+element).value;
        document.getElementById('frhotelemail').value = document.getElementById('fr1hotelemail'+element).value;
          document.getElementById('frhotelweb').value = document.getElementById('fr1hotelweb'+element).value;
           document.getElementById('frhotelrate').value = document.getElementById('fr1hotelrate'+element).value;
       document.getElementById('frhoteladd').value = document.getElementById('fr1hoteladd'+element).value;
        document.getElementById('frhotelphone').value = document.getElementById('fr1hotelphone'+element).value;
        document.getElementById('frhotelcity').value = document.getElementById('fr1hotelcity'+element).value;
        document.getElementById('frhoteldes').value = document.getElementById('fr1hoteldes'+element).value;

       
    }
    function showedit2(element){
        document.getElementById('frinsertN').style.visibility='hidden';
        document.fr.style.visibility='visible';
        document.frN.style.visibility='hidden';
        document.getElementById('frupdate').style.visibility='hidden';
        document.getElementById('frdelete').style.visibility='visible';
        document.getElementById('frhotelid').disabled= true;
       document.getElementById('frhotelidd').value = document.getElementById('fr1hotelid'+element).value;
        document.getElementById('frhotelid').value = document.getElementById('fr1hotelid'+element).value;
         document.getElementById('frhotelname').value = document.getElementById('fr1hotelname'+element).value;
        document.getElementById('frhotelemail').value = document.getElementById('fr1hotelemail'+element).value;
          document.getElementById('frhotelweb').value = document.getElementById('fr1hotelweb'+element).value;
           document.getElementById('frhotelrate').value = document.getElementById('fr1hotelrate'+element).value;
       document.getElementById('frhoteladd').value = document.getElementById('fr1hoteladd'+element).value;
        document.getElementById('frhotelphone').value = document.getElementById('fr1hotelphone'+element).value;
        document.getElementById('frhotelcity').value = document.getElementById('fr1hotelcity'+element).value;
        document.getElementById('frhoteldes').value = document.getElementById('fr1hoteldes'+element).value;
        
    }
</script>
<script language="JavaScript">
    function checkimg(element,helperMsg){
        if(element.value == "No file chosen"){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    // If the length of the element's string is 0 then display helper message
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the element's string matches the regular expression it is all numbers
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function formValidator(){
        // Make quick references to our fields
        var frhotelname = document.getElementById('frhotelname');
        var frhotelemail = document.getElementById('frhotelemail');
        var frhotelweb = document.getElementById('frhotelweb');
        var frhotelimage = document.getElementById('frhotelimage');
        var frhotelrate = document.getElementById('frhotelrate');
        var frhoteladd = document.getElementById('frhoteladd');
        var frhotelphone = document.getElementById('frhotelphone');
        var frhotelcity = document.getElementById('frhotelcity');
        var frhoteldes = document.getElementById('frhoteldes');
        // Check each input in the order that it appears in the form!
        if(notEmpty(frhotelname, "Please enter Hotel Name")){
            if(checkimg(frhotelimage, "Please choose images")){
                if(emailValidator(frhotelemail, "Please Check Email")){
                    if(notEmpty(frhotelemail, "Please Enter Email")){
                        if(notEmpty(frhotelweb, "Please enter Website")){
                            if(isNumeric(frhotelrate, "Rate is number")){
                                if(notEmpty(frhoteladd, "Please enter Hotel Address")){
                                    if(isNumeric(frhotelphone,"Phone is Number")){
                                        if(notEmpty(frhotelcity, "Please enter City")){
                                        

                                            return true;

                                      

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }


    function formValidatorN(){
        // Make quick references to our fields
        var frhotelname = document.getElementById('frhotelnameN');
        var frhotelemail = document.getElementById('frhotelemailN');
        var frhotelweb = document.getElementById('frhotelwebN');
        var frhotelimage = document.getElementById('frhotelimageN');
        var frhotelrate = document.getElementById('frhotelrateN');
        var frhoteladd = document.getElementById('frhoteladdN');
        var frhotelphone = document.getElementById('frhotelphoneN');
        var frhotelcity = document.getElementById('frhotelcityN');
        var frhoteldes = document.getElementById('frhoteldesN');
        // Check each input in the order that it appears in the form!
        if(notEmpty(frhotelname, "Please enter Hotel Name")){
            if(checkimg(frhotelimage, "Please choose images")){
                if(emailValidator(frhotelemail, "Please Check Email")){
                    if(notEmpty(frhotelemail, "Please Enter Email")){
                        if(notEmpty(frhotelweb, "Please enter Website")){
                            if(isNumeric(frhotelrate, "Rate is number")){
                                if(notEmpty(frhoteladd, "Please enter Hotel Address")){
                                    if(isNumeric(frhotelphone,"Phone is Number")){
                                        if(notEmpty(frhotelcity, "Please enter City")){


                                            return true;



                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }
</script>
<pg:pager url="paging.do" maxIndexPages="10" maxPageItems="10">
    <pg:param name="action" value="pagingHotel"/>
    <form name="fr1">
        <table cellspacing="0" cellpadding="0" border="0" width="100%"><!-- Table -->

            <tr bgcolor="#C2D1D8">
                <td><font size="3">HotelId</font></td>
                <td><font size="3">HotelName</font></td>
                <td><font size="3">Email</font></td>
                <td><font size="3">Website</font></td>
                <td><font size="3">ImageUrl</font></td>
                <td><font size="3">Rate</font></td>
                <td><font size="3">Address</font></td>
                <td><font size="3">Phone</font></td>
                <td><font size="3">City</font></td>
                <td><font size="3">Description</font></td>
                <td><font size="3">Actions</font></td>
            </tr>
            <logic:present name="list">
                <logic:iterate name="list" id="hotel">
                    <pg:item>
                        <tr bgcolor="#F0F0F0">
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" readonly size="3" name="fr1hotelid<bean:write name="hotel" property="hotelId"/>" id="fr1hotelid<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="hotelId"/>" readonly</font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="8" name="fr1hotelname<bean:write name="hotel" property="hotelId"/>" id="fr1hotelname<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="hotelName"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hotelemail<bean:write name="hotel" property="hotelId"/>" id="fr1hotelemail<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="email"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hotelweb<bean:write name="hotel" property="hotelId"/>" id="fr1hotelweb<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="website"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hotelimage<bean:write name="hotel" property="hotelId"/>" id="fr1hotelimage<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="imagesUrl"/>" ></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="2" name="fr1hotelrate<bean:write name="hotel" property="hotelId"/>" id="fr1hotelrate<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="rate"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hoteladd<bean:write name="hotel" property="hotelId"/>" id="fr1hoteladd<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="address"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="7" name="fr1hotelphone<bean:write name="hotel" property="hotelId"/>" id="fr1hotelphone<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="phone"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hotelcity<bean:write name="hotel" property="hotelId"/>" id="fr1hotelcity<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="city"/>" readonly></font></td>
                            <td><font size="1"><input type="text" style="background-color:#F0F0F0" size="5" name="fr1hoteldes<bean:write name="hotel" property="hotelId"/>" id="fr1hoteldes<bean:write name="hotel" property="hotelId"/>" value="<bean:write name="hotel" property="description"/>" readonly></font></td>


                            <td>
                                <logic:present name="listFunction">
                                    <logic:iterate name="listFunction" id="listF">
                                        <logic:equal name="listF" property="functionId" value="10">
                                            <img title="Add" src="admin/img/action_add.png" onclick="show();" style="cursor:pointer">
                                        </logic:equal>
                                        <logic:equal name="listF" property="functionId" value="11">



                                            <img title="Edit" src="admin/img/action_remove.png" onclick="showedit1('<bean:write name="hotel" property="hotelId"/>');" style="cursor:pointer">
                                        </logic:equal>
                                        <logic:equal name="listF" property="functionId" value="12">
                                            <img title="Delete" src="admin/img/action_delete.png" onclick="showedit2('<bean:write name="hotel" property="hotelId"/>')" style="cursor:pointer">
                                        </logic:equal>
                                    </logic:iterate>
                                </logic:present>
                            </td>
                        </tr>

                    </pg:item>
                </logic:iterate>
            </logic:present>
            <tr bgcolor="#C2D1D8">
                <td colspan="12"><font color="#C2D1D8"> <pg:index>
                            <pg:prev><a href="<%= pageUrl%>"><font color="#0D6AC1">[&lt;&lt;Prev]</font></a></pg:prev>
                            <pg:pages><a href="<%= pageUrl%>"><%= pageNumber%>&nbsp;&nbsp;</a></pg:pages>
                            <pg:next ><a href="<%= pageUrl%>"><font color="#0D6AC1">[Next&gt;&gt;]</font></a></pg:next>
                    </pg:index></font></td>

            </tr>
        </table>
    </form>
</pg:pager>
<form name="frN" style="visibility:hidden" action="hotelupload.do" method="post" enctype="multipart/form-data">
    <table class="tablemain" border="0">
        <tr >
            <th height="32" colspan="3" scope="col">Manager Hotel </th>
        </tr>
        <tr>
            <td width="253" height="32"><div align="right">HotelId : </div></td>
            <td width="510">
                <input type="text" name="frhotelid" id="frhotelidN" />
                <input type="hidden" name="frhotelidd" id="frhoteliddN" />
            </td>
        </tr>
        <tr>
            <td height="39"><div align="right">HotelName : </div></td>
            <td><input type="text" name="frhotelname" id="frhotelnameN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Email : </div></td>
            <td><input type="text" name="frhotelemail" id="frhotelemailN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Website : </div></td>
            <td><input type="text" name="frhotelweb" id="frhotelwebN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">ImageUrl : </div></td>
            <td><input type="file" name="frhotelimage" id="frhotelimageN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Rate : </div></td>
            <td><input type="text" name="frhotelrate" id="frhotelrateN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Address : </div></td>
            <td><input type="text" name="frhoteladd" id="frhoteladdN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Phone : </div></td>
            <td><input type="text" name="frhotelphone" id="frhotelphoneN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">City : </div></td>
            <td><input type="text" name="frhotelcity" id="frhotelcityN"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Description : </div></td>
            <td>
                <textarea name="frhoteldes" id="frhoteldesN" cols="100" rows="10"></textarea>
            </td>

        </tr>
        <tr>
            <td height="39" colspan="2"><div align="center">
                    <input type="submit" name="action" value="insertHotel" id="frinsertN" onclick="return formValidatorN();" />
                </div>
            </td>
        </tr>
    </table>

</form>
<form name="fr" style="visibility:hidden" action="Adminhotel.do" method="get" enctype="multipart/form-data">
    <table class="tablemain" border="0">
        <tr >
            <th height="32" colspan="3" scope="col">Manager Hotel </th>
        </tr>
        <tr>
            <td width="253" height="32"><div align="right">HotelId : </div></td>
            <td width="510">
                <input type="text" name="frhotelid" id="frhotelid" />
                <input type="hidden" name="frhotelidd" id="frhotelidd" />
            </td>
        </tr>
        <tr>
            <td height="39"><div align="right">HotelName : </div></td>
            <td><input type="text" name="frhotelname" id="frhotelname"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Email : </div></td>
            <td><input type="text" name="frhotelemail" id="frhotelemail"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Website : </div></td>
            <td><input type="text" name="frhotelweb" id="frhotelweb"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">ImageUrl : </div></td>
            <td><input type="file" name="frhotelimage" id="frhotelimage" /></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Rate : </div></td>
            <td><input type="text" name="frhotelrate" id="frhotelrate"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Address : </div></td>
            <td><input type="text" name="frhoteladd" id="frhoteladd"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Phone : </div></td>
            <td><input type="text" name="frhotelphone" id="frhotelphone"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">City : </div></td>
            <td><input type="text" name="frhotelcity" id="frhotelcity"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Description : </div></td>
            <td>
                <textarea name="frhoteldes" id="frhoteldes" cols="100" rows="10"></textarea>
            </td>

        </tr>
        <tr>
            <td height="39" colspan="2"><div align="center">
                    <input type="submit" name="action" value="editHotel" id="frupdate" onclick="return formValidator();" />
                    <input type="submit" name="action" value="deleteHotel" id="frdelete" />
                </div>
            </td>
        </tr>
    </table>

</form>
